import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] fib = new int[n+2];
        fib[0] = 0;
        fib[1] = 1;
        int minStep = Integer.MAX_VALUE;
        for(int i = 2; i < n+2; i++) {
            fib[i] = fib[i-1] + fib[i-2];
            if(minStep >= Math.abs(fib[i] - n)) {
                minStep = Math.abs(fib[i] - n);
            }else {
                break;
            }
        }
        if(minStep == Integer.MAX_VALUE) {
            System.out.println(0);
        }else {
            System.out.println(minStep);
        }
    }
}